home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Sound / LAME / WarpOS / src / frontend / gtkanal.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-06-12  |  49.1 KB  |  1,532 lines

  1. /*
  2.  *    GTK plotting routines source file
  3.  *
  4.  *    Copyright (c) 1999 Mark Taylor
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the
  18.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.  * Boston, MA 02111-1307, USA.
  20.  */
  21.  
  22. /* $Id: gtkanal.c,v 1.25 2001/06/11 18:49:57 markt Exp $ */
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. # include <config.h>
  26. #endif
  27.  
  28. #include <math.h>
  29. #include <gtk/gtk.h>
  30. #include <assert.h>
  31. #include "main.h"
  32. #include "lame.h"
  33. #include "lame-analysis.h"
  34. #include "get_audio.h"
  35. #include "gtkanal.h"
  36. #include "gpkplotting.h"
  37.  
  38. /* this file should be removed. The few data items accessed in 'gfc'
  39.    should be made accessable by writing a lame_set_variable() function */
  40. #include "util.h"
  41.  
  42. #ifdef WITH_DMALLOC
  43. #include <dmalloc.h>
  44. #endif
  45.  
  46. plotting_data *pinfo;
  47. plotting_data *pplot;
  48. plotting_data Pinfo[NUMPINFO];
  49.  
  50.  
  51. /* global variables for the state of the system */
  52. static gint idle_keepgoing;        /* processing of frames is ON */
  53. static gint idle_count_max;   /* number of frames to process before plotting */
  54. static gint idle_count;       /* pause & plot when idle_count=idel_count_max */
  55. static gint idle_end=0;      /* process all frames, stop at last frame  */
  56. static gint idle_back = 0;     /* set when we are displaying the old data */
  57. static int mp3done = 0;         /* last frame has been read */
  58. static GtkWidget *frameprogress; /* progress bar */ 
  59. static GtkWidget *framecounter;  /* progress counter */ 
  60.  
  61. static int subblock_draw[3] = { 1, 1, 1 };
  62.  
  63. /* main window */
  64. GtkWidget *window;
  65. /* Backing pixmap for drawing areas */
  66. GtkWidget *pcmbox;       /* PCM data plotted here */
  67. GtkWidget *winbox;       /* mpg123 synthesis data plotted here */
  68. GtkWidget *enerbox[2];   /* spectrum, gr=0,1 plotted here */
  69. GtkWidget *mdctbox[2];   /* mdct coefficients gr=0,1 plotted here */
  70. GtkWidget *sfbbox[2];    /* scalefactors gr=0,1 plotted here */
  71. GtkWidget *headerbox;    /* mpg123 header info shown here */
  72.  
  73.  
  74. struct gtkinfostruct {
  75.   int filetype;           /* input file type 0=WAV, 1=MP3 */
  76.   int msflag;             /* toggle between L&R vs M&S PCM data display */
  77.   int chflag;             /* toggle between L & R channels */
  78.   int kbflag;             /* toggle between wave # and barks */
  79.   int flag123;            /* show mpg123 frame info, OR ISO encoder frame info */
  80.   double avebits;         /* running average bits per frame */
  81.   int approxbits;         /* (approx) bits per frame */
  82.   int maxbits;            /* max bits per frame used so far*/
  83.   int totemph;            /* total of frames with de-emphasis */
  84.   int totms;              /* total frames with ms_stereo */
  85.   int totis;              /* total frames with i_stereo */
  86.   int totshort;           /* total granules with short blocks */
  87.   int totmix;             /* total granules with mixed blocks */
  88.   int pupdate;            /* plot while processing, or only when needed */
  89.   int sfblines;           /* plot scalefactor bands in MDCT plot */
  90.   int difference;         /* plot original - decoded instead of orig vs. decoded */
  91.   int totalframes;
  92. } gtkinfo;
  93.  
  94.  
  95. static lame_global_flags *gfp;
  96. lame_internal_flags *gfc;
  97.  
  98. /**********************************************************************
  99.  * read one frame and encode it 
  100.  **********************************************************************/
  101. int gtkmakeframe(void)
  102. {
  103.   int iread = 0;
  104.   static int init=0;
  105.   static int mpglag;
  106.   static short int  Buffer[2][1152];
  107.   short int  mpg123pcm[2][1152];
  108.   int ch,j;
  109.   int mp3count = 0;
  110.   int mp3out = 0;
  111.   int channels_out;
  112.   char mp3buffer[LAME_MAXMP3BUFFER];
  113.   extern plotting_data *mpg123_pinfo;  
  114.   static int frameNum=0;
  115.   int framesize = lame_get_framesize(gfp);
  116.  
  117.   channels_out = (lame_get_mode(gfp)==MONO) ? 1 : 2;
  118.  
  119.   pinfo->frameNum = frameNum;
  120.   pinfo->sampfreq = lame_get_out_samplerate ( gfp );
  121.   pinfo->framesize= framesize;
  122.   pinfo->stereo = channels_out;
  123.  
  124.   /* If the analsys code is enabled, lame will writes data into gfc->pinfo,
  125.    * and mpg123 will write data into mpg123_pinfo.  Set these so
  126.    * the libraries put this data in the right place: */
  127.   gfc->pinfo = pinfo;
  128.   mpg123_pinfo = pinfo;
  129.  
  130.   if (input_format == sf_mp1 ||
  131.       input_format == sf_mp2 ||
  132.       input_format == sf_mp3) {
  133.     iread = get_audio16(gfp,Buffer);
  134.  
  135.  
  136.     /* add a delay of framesize-DECDELAY, which will make the total delay
  137.      * exactly one frame, so we can sync MP3 output with WAV input */
  138.     for ( ch = 0; ch < channels_out; ch++ ) {
  139.       for ( j = 0; j < framesize-DECDELAY; j++ )
  140.     pinfo->pcmdata2[ch][j] = pinfo->pcmdata2[ch][j+framesize];
  141.       for ( j = 0; j < framesize; j++ )
  142.     pinfo->pcmdata2[ch][j+framesize-DECDELAY] = Buffer[ch][j];
  143.     }
  144.  
  145.     pinfo->frameNum123 = frameNum-1;
  146.     ++frameNum;
  147.  
  148.   }else {
  149.  
  150.     /* feed data to encoder until encoder produces some output */
  151.     while (lame_get_frameNum(gfp) == pinfo->frameNum) {
  152.       
  153.       if (!init) {
  154.     init=1;
  155.     mpglag=1;
  156.     lame_decode_init();
  157.       }
  158.       
  159.       iread = get_audio16(gfp,Buffer);
  160.       if (iread > framesize) {
  161.     /* NOTE: frame analyzer requires that we encode one frame 
  162.      * for each pass through this loop.  If lame_encode_buffer()
  163.      * is feed data too quickly, it will sometimes encode multiple frames
  164.      * breaking this loop.
  165.      */
  166.     fprintf(stderr,"Warning: get_audio is returning too much data.\n");
  167.       }
  168.       if (0==iread) break; /* eof */
  169.  
  170.       mp3count=lame_encode_buffer(gfp,Buffer[0],Buffer[1],iread,
  171.                   mp3buffer,(int)sizeof(mp3buffer));
  172.  
  173.       assert( !(mp3count > 0 && lame_get_frameNum(gfp) == pinfo->frameNum));
  174.       /* not possible to produce mp3 data without encoding at least 
  175.        * one frame of data which would increment frameNum */
  176.     }
  177.     frameNum = lame_get_frameNum(gfp);  /* use the internal MP3 frame counter */
  178.  
  179.     
  180.     /* decode one frame of output */
  181.     mp3out=lame_decode1(mp3buffer,mp3count,mpg123pcm[0],mpg123pcm[1]); /* re-synthesis to pcm */
  182.     /* mp3out = 0:  need more data to decode */
  183.     /* mp3out = -1:  error.  Lets assume 0 pcm output */
  184.     /* mp3out = number of samples output */
  185.     if (mp3out>0) assert(mp3out==pinfo->framesize);
  186.     if (mp3out!=0) {
  187.       /* decoded output is for frame pinfo->frameNum123 
  188.        * add a delay of framesize-DECDELAY, which will make the total delay
  189.        * exactly one frame */
  190.       pinfo->frameNum123=pinfo->frameNum-mpglag;
  191.       for ( ch = 0; ch < pinfo->stereo; ch++ ) {
  192.     for ( j = 0; j < pinfo->framesize-DECDELAY; j++ )
  193.       pinfo->pcmdata2[ch][j] = pinfo->pcmdata2[ch][j+pinfo->framesize];
  194.     for ( j = 0; j < pinfo->framesize; j++ ) {
  195.       pinfo->pcmdata2[ch][j+pinfo->framesize-DECDELAY] = 
  196.         (mp3out==-1) ? 0 : mpg123pcm[ch][j];
  197.     }
  198.       }
  199.     }else{
  200.       if (mpglag == MAXMPGLAG) {
  201.     fprintf(stderr,"READ_AHEAD set too low - not enough frame buffering.\n"
  202.            "MP3x display of input and output PCM data out of sync.\n");
  203.     fflush(stderr);
  204.       }
  205.       else mpglag++; 
  206.       pinfo->frameNum123=-1;  /* no frame output */
  207.     }
  208.   }
  209.   return iread;
  210. }
  211.  
  212.  
  213. void plot_frame(void)
  214. {
  215.   int i,j,n,ch,gr;
  216.   gdouble *xcord,*ycord;
  217.   gdouble xmx,xmn,ymx,ymn;
  218.   double *data,*data2,*data3;
  219.   char title2[80];
  220.   char label[80],label2[80];
  221.   char *title;
  222.   plotting_data *pplot1;
  223.   plotting_data *pplot2 = NULL;
  224.  
  225.   double en,samp;
  226.   int sampindex,version=0;
  227.   int barthick;
  228.   static int firstcall=1;
  229.   static GdkColor *barcolor,*color,*grcolor[2];
  230.   static GdkColor yellow,gray,cyan,magenta,orange,pink,red,green,blue,black,oncolor,offcolor;
  231.   int blocktype[2][2];
  232.   int headbits;
  233.   int mode_gr = 2;
  234.  
  235.   /* find the frame where mpg123 produced output coming from input frame
  236.    * pinfo.  i.e.:   out_frame + out_frame_lag = input_frame  */
  237.   for (i=1; i<=MAXMPGLAG; i++ ) {
  238.     if ((pplot-i)->frameNum123 == pplot->frameNum ) {
  239.       pplot2 = pplot-i;
  240.       break;
  241.     }
  242.   }
  243.   if (i > MAXMPGLAG) {
  244.     fprintf(stderr,"input/output pcm syncing problem.  should not happen!\n");
  245.     pplot2=pplot-1;
  246.   }
  247.  
  248.  
  249.   /* however, the PCM data is delayed by 528 samples in the encoder filterbanks.
  250.    * We added another 1152-528 delay to this so the PCM data is *exactly* one 
  251.    * frame behind the header & MDCT information */
  252.   pplot1 =pplot2 +1;                   /* back one frame for header info, MDCT */
  253.  
  254.   /* allocate these GC's only once */
  255.   if (firstcall) {
  256.     firstcall=0;
  257.     /*    grcolor[0] = &magenta; */
  258.     grcolor[0] = &blue;
  259.     grcolor[1] = &green;
  260.     barcolor = &gray;
  261.  
  262.     setcolor(headerbox,&oncolor,255,0,0);
  263.     setcolor(headerbox,&offcolor,175,175,175);
  264.     setcolor(pcmbox,&red,255,0,0);
  265.     setcolor(pcmbox,&pink,255,0,255);
  266.     setcolor(pcmbox,&magenta,255,0,100);
  267.     setcolor(pcmbox,&orange,255,127,0);
  268.     setcolor(pcmbox,&cyan,0,255,255);
  269.     setcolor(pcmbox,&green,0,255,0);
  270.     setcolor(pcmbox,&blue,0,0,255);
  271.     setcolor(pcmbox,&black,0,0,0);
  272.     setcolor(pcmbox,&gray,100,100,100);
  273.     setcolor(pcmbox,&yellow,255,255,0);
  274.  
  275.   }
  276.  
  277.   /*******************************************************************
  278.    * frame header info
  279.    *******************************************************************/
  280.   if (pplot1->sampfreq)
  281.     samp=pplot1->sampfreq;
  282.   else samp=1;
  283.   sampindex = SmpFrqIndex((long)samp, &version);
  284.  
  285.   ch = gtkinfo.chflag;
  286.   
  287.   headbits = 32 + ((pplot1->stereo==2) ? 256 : 136);
  288.   gtkinfo.approxbits = (pplot1->bitrate*1000*1152.0/samp) - headbits;
  289.   sprintf(title2,"%3.1fkHz %ikbs ",samp/1000,pplot1->bitrate);
  290.   gtk_text_freeze (GTK_TEXT(headerbox));
  291.   gtk_text_backward_delete(GTK_TEXT(headerbox),
  292.                 gtk_text_get_length(GTK_TEXT(headerbox)));
  293.   gtk_text_set_point(GTK_TEXT(headerbox),0);
  294.   gtk_text_insert(GTK_TEXT(headerbox),NULL,&oncolor,NULL,title2, -1);
  295.   title = " mono ";
  296.   if (2==pplot1->stereo) title = pplot1->js ? " js " : " s ";
  297.   gtk_text_insert (GTK_TEXT(headerbox), NULL, &oncolor, NULL,title, -1);
  298.   color = pplot1->ms_stereo ? &oncolor : &offcolor ; 
  299.   gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"ms ", -1);
  300.   color = pplot1->i_stereo ? &oncolor : &offcolor ; 
  301.   gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"is ", -1);
  302.  
  303.   color = pplot1->crc ? &oncolor : &offcolor ; 
  304.   gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"crc ", -1);
  305.   color = pplot1->padding ? &oncolor : &offcolor ; 
  306.   gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"pad ", -1);
  307.  
  308.   color = pplot1->emph ? &oncolor : &offcolor ; 
  309.   gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,"em ", -1);
  310.  
  311.   sprintf(title2,"bv=%i,%i ",pplot1->big_values[0][ch],pplot1->big_values[1][ch]);
  312.   gtk_text_insert (GTK_TEXT(headerbox), NULL, &black, NULL,title2, -1);
  313.  
  314.   color = pplot1->scfsi[ch] ? &oncolor : &offcolor ; 
  315.   sprintf(title2,"scfsi=%i            ",pplot1->scfsi[ch]);
  316.   gtk_text_insert (GTK_TEXT(headerbox), NULL, color, NULL,title2, -1);
  317.   if (gtkinfo.filetype) 
  318.     sprintf(title2," mdb=%i %i/NA",pplot1->maindata,pplot1->totbits);
  319.   else
  320.     sprintf(title2," mdb=%i   %i/%i",
  321.       pplot1->maindata,pplot1->totbits,pplot->resvsize);
  322.   gtk_text_insert (GTK_TEXT(headerbox), NULL, &oncolor, NULL,title2, -1);
  323.   gtk_text_thaw (GTK_TEXT(headerbox));
  324.  
  325.  
  326.  
  327.   /*******************************************************************
  328.    * block type
  329.    *******************************************************************/
  330.   for (gr = 0 ; gr < mode_gr ; gr ++) 
  331.     if (gtkinfo.flag123) 
  332.       blocktype[gr][ch]=pplot1->mpg123blocktype[gr][ch];
  333.     else blocktype[gr][ch]=pplot->blocktype[gr][ch]; 
  334.  
  335.   
  336.   /*******************************************************************
  337.    * draw the PCM data *
  338.    *******************************************************************/
  339.   n = 1600;  /* PCM frame + FFT window:   224 + 1152 + 224  */
  340.   xcord = g_malloc(n*sizeof(gdouble));
  341.   ycord = g_malloc(n*sizeof(gdouble));
  342.  
  343.  
  344.   if (gtkinfo.msflag) 
  345.     title=ch ? "Side Channel" :  "Mid Channel";
  346.   else 
  347.     title=ch ? "Right Channel" : "Left Channel";
  348.  
  349.   sprintf(title2,"%s  mask_ratio=%3.2f  %3.2f  ener_ratio=%3.2f  %3.2f",
  350.       title,
  351.       pplot->ms_ratio[0],pplot->ms_ratio[1],
  352.       pplot->ms_ener_ratio[0],pplot->ms_ener_ratio[1]);
  353.  
  354.  
  355.   ymn = -32767 ; 
  356.   ymx =  32767;
  357.   xmn = 0;
  358.   xmx = 1600-1;
  359.  
  360.   /*  0  ... 224      draw in black, connecting to 224 pixel
  361.    * 1375 .. 1599     draw in black  connecting to 1375 pixel
  362.    * 224 ... 1375     MP3 frame.  draw in blue
  363.    */
  364.  
  365.   /* draw the title */
  366.   gpk_graph_draw(pcmbox,0,xcord,ycord,xmn,ymn,xmx,ymx,1,title2,
  367.          &black);
  368.  
  369.  
  370.   /* draw some hash marks dividing the frames */
  371.   ycord[0] = ymx*.8;  ycord[1] = ymn*.8;
  372.   for (gr=0 ; gr<=2; gr++) {
  373.     xcord[0] = 223.5 + gr*576;   xcord[1] = 223.5 +gr*576;  
  374.     gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow);
  375.   }
  376.   for (gr = 0 ; gr < mode_gr ; gr++) {
  377.     if (blocktype[gr][ch]==2) 
  378.       for (i=1 ; i<=2; i++) {
  379.     xcord[0] = 223.5+gr*576 + i*192; 
  380.     xcord[1] = 223.5+gr*576 + i*192; 
  381.     gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow);
  382.       }
  383.   }
  384.   /* bars representing FFT windows */
  385.   xcord[0] = 0;       ycord[0] = ymn+3000;
  386.   xcord[1] = 1024-1;  ycord[1] = ymn+1000;
  387.   gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,grcolor[0]);
  388.   xcord[0] = 576;          ycord[0] = ymn+2000;
  389.   xcord[1] = 576+1024-1;   ycord[1] = ymn;
  390.   gpk_rectangle_draw(pcmbox,xcord,ycord,xmn,ymn,xmx,ymx,grcolor[1]);
  391.  
  392.  
  393.   /* plot PCM data */
  394.   for (i=0; i<n; i++) {
  395.     xcord[i] = i;
  396.     if (gtkinfo.msflag) 
  397.       ycord[i] = ch ? .5*(pplot->pcmdata[0][i]-pplot->pcmdata[1][i]) : 
  398.       .5*(pplot->pcmdata[0][i]+pplot->pcmdata[1][i]);
  399.     else 
  400.       ycord[i]=pplot->pcmdata[ch][i];
  401.   }
  402.  
  403.   /* skip plot if we are doing an mp3 file */
  404.   if (!gtkinfo.filetype) {
  405.     gpk_graph_draw(pcmbox,n,xcord,ycord,xmn,ymn,xmx,ymx,0,title2,&black);
  406.   }
  407.  
  408.  
  409.   /*******************************************************************/
  410.   /* draw the PCM re-synthesis data */
  411.   /*******************************************************************/
  412.   n = 1152;
  413.   /*
  414.   sprintf(title2,"Re-synthesis  mask_ratio=%3.2f  %3.2f  ener_ratio=%3.2f  %3.2f",
  415.       pplot->ms_ratio[0],pplot->ms_ratio[1],
  416.       pplot->ms_ener_ratio[0],pplot->ms_ener_ratio[1]);
  417.   */
  418.   title="Re-synthesis";
  419.   if (gtkinfo.difference) 
  420.     title="Re-synthesis difference (amplified 20db)";
  421.  
  422.  
  423.   ymn = -32767 ; 
  424.   ymx =  32767;
  425.   xmn = 0;
  426.   xmx = 1600-1; 
  427.   gpk_graph_draw(winbox,0,xcord,ycord,
  428.          xmn,ymn,xmx,ymx,1,title,&black);
  429.   /* draw some hash marks dividing the frames */
  430.   ycord[0] = ymx*.8;  ycord[1] = ymn*.8;
  431.   for (gr=0 ; gr<=2; gr++) {
  432.     xcord[0] = 223.5 + gr*576;   xcord[1] = 223.5 +gr*576;  
  433.     gpk_rectangle_draw(winbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow);
  434.   }
  435.   for (gr = 0 ; gr < 2 ; gr++) {
  436.     if (blocktype[gr][ch]==2) 
  437.       for (i=1 ; i<=2; i++) {
  438.     xcord[0] = 223.5+gr*576 + i*192; 
  439.     xcord[1] = 223.5+gr*576 + i*192; 
  440.     gpk_rectangle_draw(winbox,xcord,ycord,xmn,ymn,xmx,ymx,&yellow);
  441.       }
  442.   }
  443.  
  444.   /* this piece of PCM data from previous frame */
  445.   n = 224;
  446.   for (j=1152-n,i=0; i<n; i++,j++) {
  447.     xcord[i] = i;
  448.     if (gtkinfo.msflag) 
  449.       ycord[i] = ch ? .5*(pplot1->pcmdata2[0][j]-
  450.                           pplot1->pcmdata2[1][j]) : 
  451.       .5*(pplot1->pcmdata2[0][j]+pplot1->pcmdata2[1][j]);
  452.     else 
  453.       ycord[i]=pplot1->pcmdata2[ch][j];
  454.   }
  455.  
  456.   /* this piece of PCM data from current frame */
  457.   n = 1152;
  458.   for (i=0; i<n; i++) {
  459.     xcord[i+224] = i+224;
  460.     if (gtkinfo.msflag) 
  461.       ycord[i+224] = ch ? .5*(pplot2->pcmdata2[0][i]-pplot2->pcmdata2[1][i]) : 
  462.       .5*(pplot2->pcmdata2[0][i]+pplot2->pcmdata2[1][i]);
  463.     else 
  464.       ycord[i+224]=pplot2->pcmdata2[ch][i];
  465.   }
  466.  
  467.   n=1152+224;
  468.   if (gtkinfo.difference) {
  469.     for (i=0; i<n; i++) {
  470.       if (gtkinfo.msflag) 
  471.     ycord[i] -= ch ? .5*(pplot->pcmdata[0][i]-pplot->pcmdata[1][i]) : 
  472.     .5*(pplot->pcmdata[0][i]+pplot->pcmdata[1][i]);
  473.       else 
  474.     ycord[i] -= pplot->pcmdata[ch][i];
  475.     }
  476.     ycord[i] *= 100;
  477.   }
  478.  
  479.  
  480.   gpk_graph_draw(winbox,n,xcord,ycord,
  481.          xmn,ymn,xmx,ymx,0,title,&black);
  482.  
  483.  
  484.  
  485.  
  486.  
  487.   /*******************************************************************/
  488.   /* draw the MDCT energy spectrum */
  489.   /*******************************************************************/
  490.   for (gr = 0 ; gr < mode_gr ; gr ++) {
  491.     int bits,bits2;
  492.     char *blockname="";
  493.     switch (blocktype[gr][ch]) {
  494.     case 0: blockname = "normal";     break;
  495.     case 1:      blockname = "start";    break;
  496.     case 2:     blockname = "short";     break;
  497.     case 3:     blockname = "end";     break;
  498.     }
  499.     strcpy(label,blockname);
  500.     if (pplot1->mixed[gr][ch]) strcat(label,"(mixed)");
  501.  
  502.     
  503.     
  504.     
  505.     n = 576;
  506.     if (gtkinfo.flag123) {
  507.       data = pplot1->mpg123xr[gr][0];
  508.       data2 = pplot1->mpg123xr[gr][1];
  509.     }else{
  510.       data = pplot->xr[gr][0];
  511.       data2 = pplot->xr[gr][1];
  512.     }
  513.     
  514.  
  515.     xmn = 0;
  516.     xmx = n-1;
  517.     ymn=0;
  518.     ymx=11;
  519.  
  520.     /* draw title, erase old plot */
  521.     if (gtkinfo.flag123) {
  522.       bits=pplot1->mainbits[gr][ch];
  523.       bits2=pplot1->sfbits[gr][ch];
  524.     }else{
  525.       bits=pplot->LAMEmainbits[gr][ch];
  526.       bits2=pplot->LAMEsfbits[gr][ch];
  527.     }
  528.     sprintf(title2,"MDCT%1i(%s) bits=%i/%i ",gr,label,bits,bits2);
  529.     gpk_bargraph_draw(mdctbox[gr],0,xcord,ycord,
  530.               xmn,ymn,xmx,ymx,1,title2,0,barcolor);
  531.  
  532.     /* draw some hash marks showing scalefactor bands */
  533.     if (gtkinfo.sfblines) {
  534.       int fac,nsfb, *scalefac;
  535.       if (blocktype[gr][ch]==SHORT_TYPE) {
  536.     nsfb=SBMAX_s;
  537.     fac=3;
  538.     scalefac = gfc->scalefac_band.s;
  539.       }else{
  540.     nsfb=SBMAX_l;
  541.     fac=1;
  542.     scalefac = gfc->scalefac_band.l;
  543.       }
  544.       for (i=nsfb-7 ; i<nsfb; i++) {
  545.     ycord[0] = .8*ymx;  ycord[1] = ymn;
  546.     xcord[0] = fac*scalefac[i];
  547.     xcord[1] = xcord[0];
  548.     gpk_rectangle_draw(mdctbox[gr],xcord,ycord,xmn,ymn,xmx,ymx,&yellow);
  549.       }
  550.     }   
  551.  
  552.  
  553.  
  554.     ymn=9e20;
  555.     ymx=-9e20;
  556.     for (i=0; i<n; i++) {
  557.       double coeff;
  558.       xcord[i] = i;
  559.       if (gtkinfo.msflag){
  560.     coeff = ch ?  .5*(data[i]-data2[i]) : .5*(data[i]+data2[i]) ;
  561.       }else{
  562.     coeff = ch ? data2[i] : data[i];
  563.       }
  564.       if (blocktype[gr][ch]==SHORT_TYPE && !subblock_draw[i % 3])
  565.         coeff = 0;
  566.       ycord[i]=coeff*coeff*1e10;
  567.       ycord[i] = log10( MAX( ycord[i],(double) 1)); 
  568.  
  569. #if 0
  570.       if (ch==0) 
  571.     if (i==26) 
  572.       if (data[i]!=0)
  573.         printf("%i %i i=%i  mdct: (db) %f  %f \n",pplot->frameNum,gr,i,
  574. 10*log10(data[i]*data[i]),
  575. 10*log10(.33*(data[i-1]*data[i-1] + data[i]*data[i] + data[i+1]*data[i+1]))  
  576. );
  577. #endif
  578.  
  579.       ymx=(ycord[i] > ymx) ? ycord[i] : ymx;
  580.       ymn=(ycord[i] < ymn) ? ycord[i] : ymn;
  581.     }
  582.     /*  print the min/max
  583.     sprintf(title2,"MDCT%1i %5.2f %5.2f  bits=%i",gr,ymn,ymx,
  584.     pplot1->mainbits[gr][ch]);
  585.     */
  586.     if (gtkinfo.flag123) bits=pplot1->mainbits[gr][ch];
  587.     else bits=pplot->LAMEmainbits[gr][ch];
  588.     
  589.     
  590.     sprintf(title2,"MDCT%1i(%s) bits=%i ",gr,label,bits);
  591.  
  592.     xmn = 0;
  593.     xmx = n-1;
  594.     ymn=0;
  595.     ymx=11;
  596.     gpk_bargraph_draw(mdctbox[gr],n,xcord,ycord,
  597.               xmn,ymn,xmx,ymx,0,title2,0,barcolor);
  598.   }
  599.   
  600.  
  601.  
  602.   
  603.   /*******************************************************************
  604.    * draw the psy model energy spectrum (k space) 
  605.    * l3psy.c computes pe, en, thm for THIS granule.  
  606.    *******************************************************************/
  607.  if (gtkinfo.kbflag){
  608.     for (gr = 0 ; gr < mode_gr ; gr ++) {
  609.       n = HBLKSIZE; /* only show half the spectrum */
  610.  
  611.       data = &pplot->energy[gr][ch][0];
  612.       
  613.       ymn=9e20;
  614.       ymx=-9e20;
  615.       for (i=0; i<n; i++) {
  616.     xcord[i] = i+1;
  617.         if (blocktype[gr][ch]==SHORT_TYPE && !subblock_draw[i % 3])
  618.           ycord[i] = 0;
  619.         else
  620.       ycord[i] = log10( MAX( data[i],(double) 1));
  621.     ymx=(ycord[i] > ymx) ? ycord[i] : ymx;
  622.     ymn=(ycord[i] < ymn) ? ycord[i] : ymn;
  623.       }
  624.       for (en=0 , j=0; j<BLKSIZE ; j++) 
  625.     en += pplot->energy[gr][ch][j];
  626.  
  627.       sprintf(title2,"FFT%1i  pe=%5.2fK  en=%5.2e ",gr,
  628.           pplot->pe[gr][ch]/1000,en);
  629.  
  630.       ymn = 3;
  631.       ymx = 15;
  632.       xmn = 1;
  633.       xmx = n;
  634.       gpk_bargraph_draw(enerbox[gr],n,xcord,ycord,
  635.             xmn,ymn,xmx,ymx,1,title2,0,barcolor);
  636.       
  637.     }
  638.   }else{
  639.     /*******************************************************************
  640.      * draw the psy model energy spectrum (scalefactor bands)
  641.      *******************************************************************/
  642.     for (gr = 0 ; gr < mode_gr ; gr ++) {
  643.  
  644.       if (blocktype[gr][ch]==2) {
  645.     n = 3*SBMAX_s; 
  646.     data = &pplot->en_s[gr][ch][0];
  647.     data2 = &pplot->thr_s[gr][ch][0];
  648.     data3 = &pplot->xfsf_s[gr][ch][0];
  649.       } else {
  650.     n = SBMAX_l; 
  651.     data = &pplot->en[gr][ch][0];
  652.     data2 = &pplot->thr[gr][ch][0];
  653.     data3 = &pplot->xfsf[gr][ch][0];
  654.       }
  655.       ymn=9e20;
  656.       ymx=-9e20;
  657.       for (i=0; i<n; i++) {
  658.     xcord[i] = i+1;
  659.         if (blocktype[gr][ch]==SHORT_TYPE && !subblock_draw[i % 3])
  660.           ycord[i] = 0;
  661.         else
  662.       ycord[i] = log10( MAX( data[i],(double) 1));
  663.     /*
  664.     ymx=(ycord[i] > ymx) ? ycord[i] : ymx;
  665.     ymn=(ycord[i] < ymn) ? ycord[i] : ymn;
  666.     */
  667.       }
  668.  
  669.  
  670.  
  671.       /* en = max energy difference amoung the 3 short FFTs for this granule */
  672.       en = pplot->ers[gr][ch];
  673.       if (en>999) en=999;
  674.       sprintf(title2,"FFT%1i pe=%5.2fK/%3.1f n=%i/%3.1f/%3.1f/%3.1f",gr,
  675.           pplot->pe[gr][ch]/1000,en,pplot->over[gr][ch],
  676.           pplot->max_noise[gr][ch],
  677.           pplot->over_noise[gr][ch],
  678.           pplot->tot_noise[gr][ch]);
  679.  
  680.       barthick=3;
  681.       if (blocktype[gr][ch]==SHORT_TYPE) barthick=2;
  682.       if (!(subblock_draw[0] && subblock_draw[1] && subblock_draw[2]))
  683.     barthick=3;
  684.  
  685.       ymn = 3;
  686.       ymx = 15;
  687.       xmn = 1;
  688.       xmx = n+1; /* a little extra because of the bar thickness */
  689.       gpk_bargraph_draw(enerbox[gr],n,xcord,ycord,
  690.             xmn,ymn,xmx,ymx,1,title2,barthick,barcolor);
  691.  
  692.       for (i=0; i<n; i++) {
  693.     xcord[i] = i+1 + .20;
  694.         if (blocktype[gr][ch]==SHORT_TYPE && !subblock_draw[i % 3])
  695.           ycord[i] = 0;
  696.         else
  697.       ycord[i] = log10( MAX( data2[i], (double) 1));
  698.       }
  699.  
  700.       gpk_bargraph_draw(enerbox[gr],n,xcord,ycord,
  701.             xmn,ymn,xmx,ymx,0,title2,barthick,grcolor[gr]);
  702.  
  703.       for (i=0; i<n; i++) {
  704.     xcord[i] = i+1 + .40;
  705.         if (blocktype[gr][ch]==SHORT_TYPE && !subblock_draw[i % 3])
  706.           ycord[i] = 0;
  707.         else
  708.       ycord[i] = log10( MAX( data3[i], (double) 1));
  709.       }
  710.       gpk_bargraph_draw(enerbox[gr],n,xcord,ycord,
  711.             xmn,ymn,xmx,ymx,0,title2,barthick,&red);  
  712.  
  713.     }
  714.   }
  715.  
  716.   /*******************************************************************
  717.    * draw scalefactors 
  718.    *******************************************************************/
  719.   for (gr = 0 ; gr < mode_gr ; gr ++) {
  720.       int ggain;
  721.       if (blocktype[gr][ch]==2) {
  722.     n = 3*SBMAX_s; 
  723.     if (gtkinfo.flag123) data = pplot1->sfb_s[gr][ch];
  724.     else data = pplot->LAMEsfb_s[gr][ch];
  725.       } else {
  726.     n = SBMAX_l; 
  727.     if (gtkinfo.flag123) data = pplot1->sfb[gr][ch];
  728.     else data = pplot->LAMEsfb[gr][ch];
  729.       }
  730.  
  731.       ymn=-1;
  732.       ymx=10;
  733.       for (i=0; i<n; i++) {
  734.     xcord[i] = i+1;
  735.         if (blocktype[gr][ch]==SHORT_TYPE && !subblock_draw[i % 3])
  736.           ycord[i] = 0;
  737.         else
  738.       ycord[i] = -data[i];
  739.  
  740.     ymx=(ycord[i] > ymx-2) ? ycord[i]+2 : ymx;
  741.     ymn=(ycord[i] < ymn) ? ycord[i]-1 : ymn;
  742.       }
  743.  
  744.       if (blocktype[gr][ch]==2) {
  745.     sprintf(label2,
  746.         "SFB scale=%i preflag=%i  %i%i%i",
  747.         pplot1->scalefac_scale[gr][ch],
  748.         pplot1->preflag[gr][ch],
  749.         pplot1->sub_gain[gr][ch][0],
  750.         pplot1->sub_gain[gr][ch][1],
  751.         pplot1->sub_gain[gr][ch][2]);
  752.       }else{
  753.     sprintf(label2,"SFB scale=%i preflag=%i",pplot1->scalefac_scale[gr][ch],
  754.         pplot1->preflag[gr][ch]);
  755.       }
  756.       
  757.       if (gtkinfo.flag123) ggain = (pplot1->qss[gr][ch]);
  758.       else ggain = (pplot->LAMEqss[gr][ch]);
  759.  
  760.       sprintf(title2," ggain=%i",ggain);
  761.       strcat(label2,title2);
  762.       
  763.       xmn = 1;
  764.       xmx = n+1;
  765.       gpk_bargraph_draw(sfbbox[gr],n,xcord,ycord,
  766.             xmn,ymn,xmx,ymx,1,label2,0,grcolor[gr]);
  767.  
  768.       ycord[0] = ycord[1] = 0;
  769.       xcord[0] = 1;
  770.       xcord[1] = n+1;
  771.       gpk_rectangle_draw(sfbbox[gr],xcord,ycord,xmn,ymn,xmx,ymx,&yellow);
  772.  
  773.       
  774.     }
  775.  
  776.  
  777. }
  778.  
  779.  
  780.  
  781. static void update_progress(void)
  782. {    
  783.   char label[80];
  784.  
  785.   int tf = lame_get_totalframes(gfp);
  786.   if (gtkinfo.totalframes>0) tf=gtkinfo.totalframes;
  787.  
  788.   sprintf(label,"Frame:%4i/%4i  %6.2fs",
  789.      pplot->frameNum,(int)tf-1, pplot->frametime);
  790.   gtk_progress_set_value (GTK_PROGRESS (frameprogress), (gdouble) pplot->frameNum);
  791.   gtk_label_set_text(GTK_LABEL(framecounter),label);
  792. }
  793.  
  794.  
  795.  
  796. static void analyze(void)
  797. {
  798.     if ( idle_keepgoing) {
  799.       idle_count = 0;
  800.       idle_count_max=0;
  801.       idle_keepgoing=0;
  802.       idle_end=0;
  803.     }
  804.     plot_frame();   
  805.     update_progress(); 
  806. }
  807.  
  808. static void plotclick( GtkWidget *widget, gpointer   data )
  809. {   analyze(); }
  810.  
  811.  
  812.  
  813.  
  814. static int frameadv1(GtkWidget *widget, gpointer   data )
  815. {
  816.   int i;
  817.   if (idle_keepgoing ){
  818.     if (idle_back) {
  819.       /* frame displayed is the old frame.  to advance, just swap in new frame */
  820.       idle_back--;
  821.       pplot = &Pinfo[READ_AHEAD+idle_back];
  822.     }else{
  823.       /* advance the frame by reading in a new frame */
  824.       pplot = &Pinfo[READ_AHEAD];
  825.       if (mp3done) { 
  826.     /* dont try to read any more frames, and quit if "finish MP3" was selected */
  827.     /*    if (idle_finish) gtk_main_quit(); */
  828.     idle_count_max=0; 
  829.         idle_end=0;
  830.       } else {
  831.     /* read in the next frame */
  832.     for (i=NUMPINFO-1 ; i>0 ; i--)
  833.       memcpy(&Pinfo[i],&Pinfo[i-1],sizeof(plotting_data));
  834.     pinfo = &Pinfo[0];
  835.     pinfo->num_samples = gtkmakeframe();
  836.     if (pinfo->num_samples==0 && gtkinfo.totalframes==0) 
  837.       /* allow an extra frame to flush decoder buffers */
  838.       gtkinfo.totalframes = pinfo->frameNum +2;
  839.  
  840.     if (pinfo->sampfreq) 
  841.       pinfo->frametime = (pinfo->frameNum)*1152.0/pinfo->sampfreq;
  842.     else pinfo->frametime=0;
  843.  
  844.         /* eof? 
  845.     if (!pinfo->num_samples) if (idle_finish) gtk_main_quit();
  846.     */
  847.  
  848.     pinfo->totbits = 0;
  849.     { int gr,ch;
  850.     for (gr = 0 ; gr < 2 ; gr ++) 
  851.       for (ch = 0 ; ch < 2 ; ch ++) {
  852.         gtkinfo.totshort += (pinfo->mpg123blocktype[gr][ch]==2);
  853.         gtkinfo.totmix  += !(pinfo->mixed[gr][ch]==0);
  854.         pinfo->totbits += pinfo->mainbits[gr][ch];
  855.       }
  856.     }
  857.     if (pinfo->frameNum > 0) /* start averaging at second frame */
  858.       gtkinfo.avebits = (gtkinfo.avebits*((pinfo->frameNum)-1)
  859.       + pinfo->totbits ) /(pinfo->frameNum);
  860.  
  861.     gtkinfo.maxbits=MAX(gtkinfo.maxbits,pinfo->totbits);
  862.     gtkinfo.totemph += !(pinfo->emph==0);
  863.     gtkinfo.totms   += !(pinfo->ms_stereo==0);
  864.     gtkinfo.totis   += !(pinfo->i_stereo==0);
  865.  
  866.     if (gtkinfo.totalframes>0)
  867.       if (pplot->frameNum >= gtkinfo.totalframes-1) mp3done=1;
  868.       }
  869.     }
  870.  
  871.     idle_count++;
  872.     if (gtkinfo.pupdate) plot_frame();
  873.     update_progress();
  874.     if ((idle_count>=idle_count_max) && (! idle_end)) analyze();
  875.   }
  876.   return 1;
  877. }
  878.  
  879.  
  880. static void frameadv( GtkWidget *widget, gpointer   data )
  881. {
  882.     int adv;
  883.  
  884.     if (!strcmp((char *) data,"-1")) {
  885.       /* ignore if we've already gone back as far as possible */
  886.       if (pplot->frameNum==0 || (idle_back==NUMBACK)) return;  
  887.       idle_back++;
  888.       pplot = &Pinfo[READ_AHEAD+idle_back];
  889.       analyze();
  890.       return;
  891.     }
  892.  
  893.  
  894.     adv = 1;
  895.     if (!strcmp((char *) data,"1")) adv = 1;
  896.     if (!strcmp((char *) data,"10")) adv = 10;
  897.     if (!strcmp((char *) data,"100")) adv = 100;
  898.     if (!strcmp((char *) data,"finish")) idle_end = 1;
  899.  
  900.  
  901.     if (idle_keepgoing) {
  902.       /* already running - que up additional frame advance requests */
  903.       idle_count_max += adv; 
  904.     }
  905.     else {
  906.       /* turn on idleing */
  907.       idle_count_max = adv;
  908.       idle_count = 0;
  909.       idle_keepgoing = 1;
  910.     }
  911. }
  912.  
  913.  
  914.  
  915.  
  916. /* another callback */
  917. static void delete_event( GtkWidget *widget,
  918.                    GdkEvent  *event,
  919.            gpointer   data )
  920. {
  921.     /* set MP3 done flag in case the File/Quit menu item has been selected */
  922.     mp3done=1;
  923.  
  924.     gtk_main_quit ();
  925. }
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933. static void channel_option (GtkWidget *widget, gpointer data)
  934. {
  935.   long option;
  936.   option = (long) data;
  937.   switch (option) {
  938.   case 1:
  939.     gtkinfo.msflag=0;
  940.     gtkinfo.chflag=0; 
  941.     break;
  942.   case 2:
  943.     gtkinfo.msflag=0;
  944.     gtkinfo.chflag=1; 
  945.     break;
  946.   case 3:
  947.     gtkinfo.msflag=1;
  948.     gtkinfo.chflag=0; 
  949.     break;
  950.   case 4:
  951.     gtkinfo.msflag=1;
  952.     gtkinfo.chflag=1; 
  953.   }
  954.   analyze();
  955. }
  956. static void spec_option (GtkWidget *widget, gpointer data)
  957. {
  958.   long option;
  959.   option = (long) data;
  960.   switch (option) {
  961.   case 1:
  962.     gtkinfo.kbflag=0;
  963.     break;
  964.   case 2:
  965.     gtkinfo.kbflag=1;
  966.     break;
  967.   case 3:
  968.     gtkinfo.flag123=0;
  969.     break;
  970.   case 4:
  971.     gtkinfo.flag123=1;
  972.     break;
  973.   case 5:
  974.     gtkinfo.pupdate=1;
  975.     break;
  976.   case 6:
  977.     gtkinfo.pupdate=0;
  978.     break;
  979.   case 7:
  980.     gtkinfo.sfblines = !gtkinfo.sfblines;
  981.     break;
  982.   case 8:
  983.     gtkinfo.difference = !gtkinfo.difference;
  984.     break;
  985.   }
  986.   analyze();
  987. }
  988.  
  989. static gint key_press_event (GtkWidget *widget, GdkEventKey *event)
  990. {
  991.     // is a switch() statement in lame forbidden?
  992.   if (event->keyval == '1') {
  993.     subblock_draw[0] = 1;
  994.     subblock_draw[1] = 0;
  995.     subblock_draw[2] = 0;
  996.     analyze();
  997.   }
  998.   else if (event->keyval == '2') {
  999.     subblock_draw[0] = 0;
  1000.     subblock_draw[1] = 1;
  1001.     subblock_draw[2] = 0;
  1002.     analyze();
  1003.   }
  1004.   else if (event->keyval == '3') {
  1005.     subblock_draw[0] = 0;
  1006.     subblock_draw[1] = 0;
  1007.     subblock_draw[2] = 1;
  1008.     analyze();
  1009.   }
  1010.   else if (event->keyval == '0') {
  1011.     subblock_draw[0] = 1;
  1012.     subblock_draw[1] = 1;
  1013.     subblock_draw[2] = 1;
  1014.     analyze();
  1015.   }
  1016.   /* analyze(); */  /* dont redraw entire window for every key! */
  1017.   return 0;
  1018. }
  1019.  
  1020.  
  1021.  
  1022. static void text_window (GtkWidget *widget, gpointer data)
  1023. {
  1024.   long option;
  1025.   GtkWidget *hbox,*vbox,*button,*box;
  1026.   GtkWidget *textwindow,*vscrollbar;
  1027.   char text[256];
  1028.  
  1029.   option = (long) data;
  1030.   
  1031.   textwindow = gtk_window_new(GTK_WINDOW_DIALOG);
  1032.   gtk_signal_connect_object (GTK_OBJECT (window), "delete_event",
  1033.               GTK_SIGNAL_FUNC(gtk_widget_destroy),
  1034.               GTK_OBJECT (textwindow));
  1035.  
  1036.   gtk_container_set_border_width (GTK_CONTAINER (textwindow), 0);
  1037.   vbox = gtk_vbox_new(FALSE,0);
  1038.   hbox = gtk_hbox_new(FALSE,0);
  1039.  
  1040.   button = gtk_button_new_with_label ("close");
  1041.   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  1042.                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
  1043.                  GTK_OBJECT (textwindow));
  1044.  
  1045.   box = gtk_text_new (NULL, NULL);
  1046.   gtk_text_set_editable (GTK_TEXT (box), FALSE);
  1047.   vscrollbar = gtk_vscrollbar_new (GTK_TEXT(box)->vadj);
  1048.  
  1049.  
  1050.   switch (option) {
  1051.   case 0: 
  1052.     gtk_window_set_title (GTK_WINDOW (textwindow), "Documentation");
  1053.     gtk_widget_set_usize(box,450,500); 
  1054.     gtk_text_set_word_wrap(GTK_TEXT(box),TRUE);
  1055.     // text should be moved outside this function, may be in a separate file
  1056.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1057.         "Frame header information: "\
  1058.         "First the bitrate, sampling frequency and mono, stereo or jstereo "\
  1059.         "indicators are displayed .  If the bitstream is jstereo, then mid/side "\
  1060.         "stereo or intensity stereo may be on (indicated in red).  If "\
  1061.         "de-emphasis is used, this is also indicated in red.  The mdb value is "\
  1062.         "main_data_begin.  The encoded data starts this many bytes *before* the "\
  1063.         "frame header.  A large value of mdb means the bitstream has saved some "\
  1064.         "bits into the reservoir, which it may allocate for some future frame. "\
  1065.         "The two numbers after mdb are the size (in bits) used to encode the "\
  1066.         "MDCT coefficients for this frame, followed byt the size of the bit "\
  1067.         "resevoir before encoding this frame.  The maximum frame size and a "\
  1068.         "running average are given in the Stats pull down menu.  A large "\
  1069.         "maximum frame size indicates the bitstream has made use of the bit "\
  1070.         "reservoir. \n\n",-1);
  1071.  
  1072.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1073.         "PCM data (top graph): "\
  1074.         "The PCM data is plotted in black.  The layer3 frame is divided into 2 "\
  1075.         "granules of 576 samples (marked with yellow vertical lines).  In the "\
  1076.         "case of normal, start and stop blocks, the MDCT coefficients for each "\
  1077.         "granule are computed using a 1152 sample window centered over the "\
  1078.         "granule.  In the case of short blocks, the granule is further divided "\
  1079.         "into 3 blocks of 192 samples (also marked with yellow vertical lines)."\
  1080.         "The MDCT coefficients for these blocks are computed using 384 sample "\
  1081.         "windows centered over the 192 sample window.  (This info not available "\
  1082.         "when analyzing .mp3 files.)  For the psycho-acoustic model, a windowed "\
  1083.         "FFT is computed for each granule.  The range of these windows "\
  1084.         "is denoted by the blue and green bars.\n\n",-1);
  1085.  
  1086.         gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1087.         "PCM re-synthesis data (second graph): "\
  1088.         "Same as the PCM window described above.  The data displayed is the "\
  1089.         "result of encoding and then decoding the original sample. \n\n",-1);
  1090.  
  1091.         gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1092.         "MDCT windows: "\
  1093.         "Shows the energy in the MDCT spectrum for granule 0 (left window) "\
  1094.         "and granule 1 (right window).  The text also shows the blocktype "\
  1095.         "used, the number of bits used to encode the coefficients and the "\
  1096.         "number of extra bits allocated from the reservoir.  The MDCT pull down "\
  1097.         "window will toggle between the original unquantized MDCT coefficients "\
  1098.         "and the compressed (quantized) coefficients.\n\n",-1); 
  1099.  
  1100.         gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1101.         "FFT window: "\
  1102.         "The gray bars show the energy in the FFT spectrum used by the "\
  1103.         "psycho-acoustic model.  Granule 0 is in the left window, granule 1 in "\
  1104.         "the right window.  The green and blue bars show how much distortion is "\
  1105.         "allowable, as computed by the psycho-acoustic model. The red bars show "\
  1106.         "the actual distortion after encoding.  There is one FFT for each "\
  1107.         "granule, computed with a 1024 Hann window centered over the "\
  1108.         "appropriate granule.  (the range of this 1024 sample window is shown "\
  1109.         "by the blue and green bars in the PCM data window).  The Spectrum pull "\
  1110.         "down window will toggle between showing the energy in equally spaced "\
  1111.         "frequency domain and the scale factor bands used by layer3.  Finally, "\
  1112.         "the perceptual entropy, total energy and number of scalefactor bands "\
  1113.         "with audible distortion is shown.  (This info not available when "\
  1114.         "analyzing .mp3 files.)",-1);
  1115.  
  1116.     break;
  1117.   case 1:
  1118.     /* Set the about box information */
  1119.     gtk_window_set_title (GTK_WINDOW (textwindow), "About");
  1120.     gtk_widget_set_usize(box,350,260);
  1121.  
  1122.     sprintf(text,"LAME version %s \n%s\n\n",get_lame_version(),get_lame_url());
  1123.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1124.  
  1125.     sprintf(text,"psycho-acoustic model:  GPSYCHO version %s\n",get_psy_version());
  1126.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1127.     
  1128.     sprintf(text,"frame analyzer: MP3x version %s\n\n",get_mp3x_version());
  1129.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1130.     
  1131.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1132.             "decoder:  mpg123/mpglib  .59q  \nMichael Hipp (www.mpg123.de)\n\n",-1);
  1133.     
  1134.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,
  1135.     "Encoder, decoder & psy-models based on ISO\ndemonstration source. ",-1);
  1136.     break;
  1137.  
  1138.   case 2:
  1139.     gtk_window_set_title (GTK_WINDOW (textwindow), "Statistics");
  1140.     gtk_widget_set_usize(box,350,260);
  1141.     sprintf(text,"frames processed so far: %i \n",Pinfo[0].frameNum+1);
  1142.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1143.     sprintf(text,"granules processed so far: %i \n\n",4*(Pinfo[0].frameNum+1));
  1144.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1145.     sprintf(text,"mean bits/frame (approximate): %i\n",
  1146.         gtkinfo.approxbits);
  1147.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1148.     sprintf(text,"mean bits/frame (from LAME): %i\n",
  1149.         4*Pinfo[0].mean_bits);
  1150.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1151.     sprintf(text,"bitsize of largest frame: %i \n",gtkinfo.maxbits);
  1152.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1153.     sprintf(text,"average bits/frame: %3.1f \n\n",gtkinfo.avebits);
  1154.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1155.     sprintf(text,"ms_stereo frames: %i \n",gtkinfo.totms);
  1156.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1157.     sprintf(text,"i_stereo frames: %i \n",gtkinfo.totis);
  1158.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1159.     sprintf(text,"de-emphasis frames: %i \n",gtkinfo.totemph);
  1160.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1161.     sprintf(text,"short block granules: %i \n",gtkinfo.totshort);
  1162.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1163.     sprintf(text,"mixed block granules: %i \n",gtkinfo.totmix);
  1164.     gtk_text_insert(GTK_TEXT(box),NULL,NULL,NULL,text,-1);
  1165.     break;
  1166.   }
  1167.  
  1168.  
  1169.  
  1170.   gtk_widget_show (vscrollbar);
  1171.   gtk_widget_show (box);
  1172.   gtk_widget_show (vbox);
  1173.   gtk_widget_show (hbox);
  1174.   gtk_widget_show (button);
  1175.  
  1176.   gtk_box_pack_start (GTK_BOX(hbox), box, FALSE, TRUE, 0);
  1177.   gtk_box_pack_start(GTK_BOX(hbox), vscrollbar, FALSE, FALSE, 0);
  1178.   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
  1179.   gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, TRUE, 0);
  1180.   gtk_container_add (GTK_CONTAINER (textwindow), vbox); 
  1181.   gtk_widget_show(textwindow);
  1182.  
  1183. }
  1184.  
  1185.  
  1186.  
  1187.  
  1188. /* #include <strings.h>*/
  1189.  
  1190.  
  1191. /* This is the GtkItemFactoryEntry structure used to generate new menus.
  1192.    Item 1: The menu path. The letter after the underscore indicates an
  1193.            accelerator key once the menu is open.
  1194.    Item 2: The accelerator key for the entry
  1195.    Item 3: The callback function.
  1196.    Item 4: The callback action.  This changes the parameters with
  1197.            which the function is called.  The default is 0.
  1198.    Item 5: The item type, used to define what kind of an item it is.
  1199.            Here are the possible values:
  1200.  
  1201.            NULL               -> "<Item>"
  1202.            ""                 -> "<Item>"
  1203.            "<Title>"          -> create a title item
  1204.            "<Item>"           -> create a simple item
  1205.            "<CheckItem>"      -> create a check item
  1206.            "<ToggleItem>"     -> create a toggle item
  1207.            "<RadioItem>"      -> create a radio item
  1208.            <path>             -> path of a radio item to link against
  1209.            "<Separator>"      -> create a separator
  1210.            "<Branch>"         -> create an item to hold sub items
  1211.            "<LastBranch>"     -> create a right justified branch 
  1212. */
  1213.  
  1214.  
  1215. #define C(chr)         "<control>" #chr
  1216. #define func(name)   (GtkItemFactoryCallback) (name)
  1217.  
  1218. static const GtkItemFactoryEntry menu_items [] = {
  1219.     { "/_File"                      , NULL, NULL                , 0, "<Branch>" },
  1220. #if 0
  1221.     { "/File/_New"                  , C(N), func(print_hello)   , 0, NULL },
  1222.     { "/File/_Open"                 , C(O), func(print_hello)   , 0, NULL },
  1223.     { "/File/_Save"                 , C(S), func(print_hello)   , 0, NULL },
  1224.     { "/File/Save _As"              , NULL, NULL                , 0, NULL },
  1225.     { "/File/sep1"                  , NULL, NULL                , 0, "<Separator>" },
  1226.     { "/File/Quit"                  , C(Q), func(gtk_main_quit) , 0, NULL }, 
  1227. #endif
  1228.     { "/File/_Quit"                 , C(Q), func(delete_event)  , 0, NULL }, 
  1229.  
  1230.     { "/_Plotting"                  , NULL, NULL                , 0, "<Branch>" },
  1231.     { "/Plotting/_While advancing"  , NULL, func(spec_option)   , 5, NULL },
  1232.     { "/Plotting/_After advancing"  , NULL, func(spec_option)   , 6, NULL },
  1233.     { "/Plotting/Toggle SFB lines"  , NULL, func(spec_option)   , 7, NULL },
  1234.     { "/Plotting/Toggle orig-diff"  , NULL, func(spec_option)   , 8, NULL },
  1235.   
  1236.     { "/_Channel"                   , NULL, NULL                , 0, "<Branch>" },
  1237.     { "/Channel/show _Left"         , NULL, func(channel_option), 1, NULL },
  1238.     { "/Channel/show _Right"        , NULL, func(channel_option), 2, NULL },
  1239.     { "/Channel/show _Mid"          , NULL, func(channel_option), 3, NULL },
  1240.     { "/Channel/show _Side"         , NULL, func(channel_option), 4, NULL },
  1241.  
  1242.     { "/_Spectrum"                  , NULL, NULL                , 0, "<Branch>" },
  1243.     { "/Spectrum/_Scalefactor bands", NULL, func(spec_option)   , 1, NULL },
  1244.     { "/Spectrum/_Wave number"      , NULL, func(spec_option)   , 2, NULL },
  1245.  
  1246.     { "/_MDCT"                      , NULL, NULL                , 0, "<Branch>" },
  1247.     { "/MDCT/_Original"             , NULL, func(spec_option)   , 3, NULL },
  1248.     { "/MDCT/_Compressed"           , NULL, func(spec_option)   , 4, NULL },
  1249.     { "/MDCT/_Toggle SFB lines"     , NULL, func(spec_option)   , 7, NULL },
  1250.  
  1251.     { "/_Stats"                     , NULL, NULL                , 0, "<Branch>" },
  1252.     { "/Stats/_Show"                , NULL, func(text_window)   , 2, NULL },
  1253.  
  1254.     { "/_Help"                      , NULL, NULL                , 0, "<LastBranch>" },
  1255.     { "/_Help/_Documentation"       , NULL, func(text_window)   , 0, NULL },
  1256.     { "/_Help/_About"               , NULL, func(text_window)   , 1, NULL },
  1257. };
  1258.  
  1259. #undef C
  1260. #undef func
  1261.  
  1262.  
  1263. static void get_main_menu(GtkWidget *windows, GtkWidget ** menubar) {
  1264.   unsigned int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
  1265.   GtkItemFactory *item_factory;
  1266.   GtkAccelGroup *accel_group;
  1267.  
  1268.   accel_group = gtk_accel_group_new();
  1269.  
  1270.   /* This function initializes the item factory.
  1271.      Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,
  1272.               or GTK_TYPE_OPTION_MENU.
  1273.      Param 2: The path of the menu.
  1274.      Param 3: A pointer to a gtk_accel_group.  The item factory sets up
  1275.               the accelerator table while generating menus.
  1276.   */
  1277.  
  1278.   item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", 
  1279.                        accel_group);
  1280.  
  1281.   /* This function generates the menu items. Pass the item factory,
  1282.      the number of items in the array, the array itself, and any
  1283.      callback data for the the menu items. */
  1284.   gtk_item_factory_create_items(item_factory, nmenu_items, (GtkItemFactoryEntry*)menu_items, NULL);
  1285.  
  1286.   /* Attach the new accelerator group to the window. */
  1287.   gtk_accel_group_attach (accel_group, GTK_OBJECT (windows));
  1288.  
  1289.   if (menubar)
  1290.     /* Finally, return the actual menu bar created by the item factory. */ 
  1291.     *menubar = gtk_item_factory_get_widget(item_factory, "<main>");
  1292. }
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309. int gtkcontrol(lame_global_flags *gfp2,char *inPath)
  1310. {
  1311.     /* GtkWidget is the storage type for widgets */
  1312.     GtkWidget *button;
  1313.     GtkAdjustment *adj;
  1314.     GtkWidget *mbox;        /* main box */
  1315.     GtkWidget *box1;        /* frame control buttons go */
  1316.     GtkWidget *box2;        /* frame counters */
  1317.     GtkWidget *box3;        /* frame header info */
  1318.     GtkWidget *table;       /* table for all the plotting areas */
  1319.     GtkWidget *menubar;
  1320.  
  1321.     gint tableops,graphx,graphy;
  1322.     char frameinfo[80];
  1323.  
  1324.     graphx = 600;  /* minimum allowed size of pixmap */
  1325.     graphy = 95;
  1326.  
  1327.     gfp=gfp2;
  1328.     gfc=gfp->internal_flags;
  1329.  
  1330.     /* set some global defaults/variables */
  1331.     gtkinfo.filetype = (input_format == sf_mp1 ||
  1332.                         input_format == sf_mp2 ||
  1333.                         input_format == sf_mp3);
  1334.     gtkinfo.msflag=0;
  1335.     gtkinfo.chflag=0;
  1336.     gtkinfo.kbflag=0;
  1337.     gtkinfo.flag123 = (input_format == sf_mp1 ||
  1338.                        input_format == sf_mp2 ||
  1339.                        input_format == sf_mp3); /* MP3 file=use mpg123 output */
  1340.     gtkinfo.pupdate=0;
  1341.     gtkinfo.avebits = 0;
  1342.     gtkinfo.maxbits = 0;
  1343.     gtkinfo.approxbits = 0;
  1344.     gtkinfo.totemph = 0;
  1345.     gtkinfo.totms = 0;
  1346.     gtkinfo.totis = 0;
  1347.     gtkinfo.totshort = 0;
  1348.     gtkinfo.totmix = 0;
  1349.     gtkinfo.sfblines= 1;
  1350.     gtkinfo.difference= 0;
  1351.     gtkinfo.totalframes = 0;
  1352.  
  1353.     memset((char *) Pinfo, 0, sizeof(Pinfo));
  1354.     pplot = &Pinfo[READ_AHEAD];
  1355.  
  1356.     strcpy(frameinfo,"MP3x: ");
  1357.     strncat(frameinfo,inPath,70);
  1358.  
  1359.     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  1360.     gtk_window_set_title (GTK_WINDOW (window), frameinfo);
  1361.     gtk_signal_connect (GTK_OBJECT (window), "delete_event",
  1362.             GTK_SIGNAL_FUNC (delete_event), NULL);
  1363.  
  1364.     gtk_signal_connect_object (GTK_OBJECT (window), "key_press_event",
  1365.               GTK_SIGNAL_FUNC(key_press_event),
  1366.               GTK_OBJECT (window));
  1367.  
  1368.     gtk_container_set_border_width (GTK_CONTAINER (window), 0);
  1369.  
  1370.  
  1371.     mbox = gtk_vbox_new(FALSE, 0);
  1372.  
  1373.  
  1374.     /* layout of mbox */
  1375.     box1 = gtk_hbox_new(FALSE, 0);
  1376.     box2 = gtk_hbox_new(FALSE, 0);
  1377.     box3 = gtk_hbox_new(FALSE, 0);
  1378.     table = gtk_table_new (5, 2, FALSE);
  1379.     tableops = GTK_FILL | GTK_EXPAND | GTK_SHRINK;
  1380.     get_main_menu(window, &menubar);
  1381.  
  1382.     gtk_box_pack_start(GTK_BOX(mbox), menubar, FALSE, TRUE, 0);
  1383.     gtk_box_pack_end (GTK_BOX (mbox), box1, FALSE, TRUE, 0);
  1384.     gtk_box_pack_end(GTK_BOX (mbox),box2, FALSE, TRUE, 0);
  1385.     gtk_box_pack_start(GTK_BOX (mbox),box3, FALSE, TRUE, 0);
  1386.     gtk_box_pack_start (GTK_BOX (mbox), table, TRUE, TRUE, 0);
  1387.     gtk_container_add (GTK_CONTAINER (window), mbox); 
  1388.  
  1389.  
  1390.     /*********************************************************************/
  1391.     /* stuff in box3  frame header info */
  1392.     /*********************************************************************/
  1393.     /*
  1394.     headerbox = gtk_label_new(" ");
  1395.     gtk_label_set_justify(GTK_LABEL(headerbox),GTK_JUSTIFY_LEFT); 
  1396.     */
  1397.     headerbox = gtk_text_new (NULL, NULL);
  1398.     gtk_text_set_editable (GTK_TEXT (headerbox), FALSE);
  1399.     gtk_widget_set_usize(headerbox,200,20);
  1400.     gtk_widget_show (headerbox);
  1401.     gtk_box_pack_start(GTK_BOX (box3),headerbox, TRUE, TRUE, 0);
  1402.     
  1403.  
  1404.  
  1405.     /*********************************************************************/
  1406.     /* stuff in box2   frame counters  */
  1407.     /*********************************************************************/
  1408.     framecounter = gtk_label_new("");
  1409.     gtk_widget_show(framecounter);
  1410.     gtk_box_pack_start(GTK_BOX (box2),framecounter, FALSE, TRUE, 0);
  1411.  
  1412.     adj = (GtkAdjustment *) gtk_adjustment_new (0, 0,(gint) lame_get_totalframes(gfp)-1, 0, 0, 0);
  1413.     frameprogress = gtk_progress_bar_new_with_adjustment (adj);
  1414.     /* Set the format of the string that can be displayed in the
  1415.      * trough of the progress bar:
  1416.      * %p - percentage
  1417.      * %v - value
  1418.      * %l - lower range value
  1419.      * %u - upper range value */
  1420.     gtk_progress_set_format_string (GTK_PROGRESS (frameprogress), "%p%%");
  1421.     gtk_progress_set_value (GTK_PROGRESS (frameprogress), (gdouble) 0);
  1422.     gtk_progress_set_show_text (GTK_PROGRESS (frameprogress),TRUE);
  1423.     gtk_widget_show (frameprogress);
  1424.     gtk_box_pack_end (GTK_BOX (box2), frameprogress, FALSE, TRUE, 0);
  1425.  
  1426.  
  1427.  
  1428.     /*********************************************************************/
  1429.     /* stuff in box1  buttons along bottom */
  1430.     /*********************************************************************/
  1431.     button = gtk_button_new_with_label ("-1");
  1432.     gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1433.             GTK_SIGNAL_FUNC (frameadv), (gpointer) "-1");
  1434.     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  1435.     gtk_widget_show(button);
  1436.  
  1437.     button = gtk_button_new_with_label ("+1");
  1438.     gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1439.             GTK_SIGNAL_FUNC (frameadv), (gpointer) "1");
  1440.     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  1441.     gtk_widget_show(button);
  1442.  
  1443.     button = gtk_button_new_with_label ("+10");
  1444.     gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1445.             GTK_SIGNAL_FUNC (frameadv), (gpointer) "10");
  1446.     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  1447.     gtk_widget_show(button);
  1448.  
  1449.     button = gtk_button_new_with_label ("+100");
  1450.     gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1451.             GTK_SIGNAL_FUNC (frameadv), (gpointer) "100");
  1452.     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  1453.     gtk_widget_show(button);
  1454.  
  1455.     button = gtk_button_new_with_label ("last frame");
  1456.     gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1457.             GTK_SIGNAL_FUNC (frameadv), (gpointer) "finish");
  1458.     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  1459.     gtk_widget_show(button);
  1460.  
  1461.     button = gtk_button_new_with_label ("stop/plot");
  1462.     gtk_signal_connect (GTK_OBJECT (button), "clicked",
  1463.             GTK_SIGNAL_FUNC (plotclick), NULL);
  1464.     gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  1465.     gtk_widget_show(button);
  1466.  
  1467.  
  1468.     /*********************************************************************/
  1469.     /* stuff in table.  all the plotting windows */
  1470.     /*********************************************************************/
  1471.     pcmbox = gpk_plot_new(graphx,graphy);
  1472.     gtk_table_attach (GTK_TABLE(table),pcmbox,0,2,0,1,tableops,tableops,2,2 );
  1473.     gtk_widget_show (pcmbox);
  1474.  
  1475.     winbox = gpk_plot_new(graphy,graphy);
  1476.     gtk_table_attach(GTK_TABLE(table),winbox,0,2,1,2,tableops,tableops,2,2);
  1477.     gtk_widget_show (winbox);
  1478.  
  1479.  
  1480.     mdctbox[0] = gpk_plot_new(graphy,graphy);
  1481.     gtk_table_attach(GTK_TABLE(table),mdctbox[0],0,1,2,3,tableops,tableops,2,2);
  1482.     gtk_widget_show (mdctbox[0]);
  1483.  
  1484.     mdctbox[1] = gpk_plot_new(graphy,graphy);
  1485.     gtk_table_attach (GTK_TABLE(table),mdctbox[1],1,2,2,3,tableops,tableops,2,2);
  1486.     gtk_widget_show (mdctbox[1]);
  1487.  
  1488.     enerbox[0] = gpk_plot_new(graphy,graphy);
  1489.     gtk_table_attach(GTK_TABLE(table),enerbox[0],0,1,3,4,tableops,tableops,2,2);
  1490.     gtk_widget_show (enerbox[0]);
  1491.  
  1492.     enerbox[1] = gpk_plot_new(graphy,graphy);
  1493.     gtk_table_attach (GTK_TABLE(table),enerbox[1],1,2,3,4,tableops,tableops,2,2);
  1494.     gtk_widget_show (enerbox[1]);
  1495.  
  1496.     sfbbox[0] = gpk_plot_new(graphy,graphy);
  1497.     gtk_table_attach(GTK_TABLE(table),sfbbox[0],0,1,4,5,tableops,tableops,2,2);
  1498.     gtk_widget_show (sfbbox[0]);
  1499.  
  1500.     sfbbox[1] = gpk_plot_new(graphy,graphy);
  1501.     gtk_table_attach (GTK_TABLE(table),sfbbox[1],1,2,4,5,tableops,tableops,2,2);
  1502.     gtk_widget_show (sfbbox[1]);
  1503.  
  1504.  
  1505.  
  1506.  
  1507.     gtk_idle_add((GtkFunction) frameadv1, NULL);
  1508.     gtk_widget_show(menubar); 
  1509.     gtk_widget_show(box2); 
  1510.     gtk_widget_show(box3); 
  1511.     gtk_widget_show(table);
  1512.     gtk_widget_show(box1);
  1513.     gtk_widget_show (mbox);
  1514.     gtk_widget_show (window);     /* show smallest allowed window */
  1515.  
  1516.     /* make window bigger.   */ 
  1517.     /* now the user will be able to shrink it, if desired */
  1518.     /* gtk_widget_set_usize(mbox,500,500);  */
  1519.     /* gtk_widget_show (window); */     /* show smallest allowed window */
  1520.  
  1521.  
  1522.     
  1523.     idle_keepgoing=1;             /* processing of frames is ON */
  1524.     idle_count_max=READ_AHEAD+1;  /* number of frames to process before plotting */
  1525.     idle_count=0;                 /* pause & plot when idle_count=idle_count_max */
  1526.  
  1527.     gtk_main ();
  1528.     assert(mp3done);
  1529.     return(0);
  1530. }
  1531.  
  1532.